package com.Controller;

import com.Service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/product")
public class GroupProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/list")
    public String listAll(Model model) {
        model.addAttribute("products", productService.findAll());
        return "product_list";
    }

    @GetMapping("/search")
    public String search(@RequestParam String keyword, Model model) {
        model.addAttribute("products", productService.search(keyword));
        return "product_list";
    }

    @GetMapping("/category/{cid}")
    public String listByCategory(@PathVariable Long cid, Model model) {
        model.addAttribute("products", productService.findByCategoryId(cid));
        return "product_list";
    }
}